home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Loadstar 128 15
/
q15.d81
/
t.zero page 15
< prev
next >
Wrap
Text File
|
2022-08-28
|
4KB
|
92 lines
Z E R O P A G E : PUTTING A DIRECTORY IN STRINGS
by Fender Tucker
Back in the old days programs that accessed the disk drive for files
used to expect that the user knew which file he wanted to load. The prompt
would say, "Enter filename: ". But then things got a little more
sophisticated, especially when the C-128 came along, and then they'd say,
"Enter filename (or press D for directory)". This meant that instead of
remembering filenames for hours or days, you only had to remember them for
the few seconds it took to get back to the input prompt from looking at the
directory.
The only problem is that since filenames must be EXACT it's sometimes
hard to remember a filename even for a few seconds. That's why the current
philosophy about filename requestors is that the program should read the
disk directory and place the relevant filenames in a scrolling menu so the
user only needs to highlight the filename he wants. No typing is necessary.
I doubt that anyone prefers the old way over the new way.
There are two programs on this issue that have routines that read a
directory then selectively put relevant filenames into string arrays. I
will describe them both and you can choose which one you prefer for your
program. They both should work on any type of drive, no matter what its
device number is. These routines don't include the scrollable menu; they
just put the filenames in subscripted strings for you, as the programmer, to
handle as you wish.
The first is from HURRICANE TRACKER, which is a BASIC 8 program and
can't be LISTed without the BASIC 8 disk. The routine looks like:
2110 n=0:b$="":open2,dv,0,"$0:h.*"
2120 fori=1to36:get#2,a$:next
2130 get#2,a$:ifst<>0then2220
2140 ifa$<>chr$(34)then2130
2150 get#2,a$:ifst<>0then2220
2160 ifa$<>chr$(34)thenb$=b$+a$:goto2150
2170 n=n+1
2180 f$(n)=b$:b$=""
2190 get#2,a$:ifa$<>""then2190
2200 get#2,a$,a$,a$,a$
2210 ifst=0then2130
2220 close2
After this routine is invoked, all of the filenames on the disk that begin
with "h." will be in f$(n), beginning with f$(1). The variable n will hold
the number of files found. Note the use of wildcards in the OPEN command in
line 2110. If all files on the disk were wanted, then just "$" would be in
quotes. See your drive manual for more information about wildcards and how
they can be used for selective directories.
Line 2120 bypasses the header name. The variable dv is the device
number. The rest of the code concerns using the double quotes -- chr$(34)
-- that surround each filename. The idea is to put what's between each open
quote and close quote into f$(n), and throw away everything else.
This routine will work in the 64 mode, too. It's quite generic.
The next routine is from Marshall Cook's EASY JACKET. It's specific
for the C-128 and uses some BASIC 7.0 commands.
3100 n=0:b$="":b=65445:open2,dv,0,"$":sysdec("ffc6"),,2
3110 fori=1to4:sysb:next
3120 fori=1to2:sysb:next
3130 sysb:rrega:ifa=34thenff=1-ff:ifff=0then3150
3140 ifff=1thenb$=b$+chr$(a)
3150 ifa>0then3130
3160 f$(n)=b$:b$="":n=n+1:fori=1to2:sysb:next
3170 rregde:ifde>0then3120
3180 sysdec("ffcc"):close2:n=n-2
Both routines take the about the same amount of time, about a second per
filename. This second method places the header name into f$(0) while the
first one doesn't. Make sure you DIMension f$(n) large enough for your
purposes. 1541 drives can hold 144 files, 1571's can hold 288, and 1581's
can hold 296. However, if there's a chance your program will need to handle
over 100 filenames, it's probably time for an ML routine. Making users wait
100 seconds for anything is not a 90's way to program.
Programmers, consider using one of these routines (or a better version
if you have one) in your programs and allow your users to choose files from
a menu, rather than having to type in remembered filenames. Some of us are
getting too old to remember our anniversaries, much less filenames.
I've placed a BASIC file called "dir stringers" on Side One that has
these two routines in it. Just delete the one you don't want and add the
other to your program, renumbering if necessary.
FT
**** End of Text ****